mIRC Syntax Tutorial
by Yochai Timmer
I've seen a lot of people who come into mIRC scripting help channels and
don't even know the basic
syntax for any of the events they use.
I've organized mIRC's controls by topics, so it will be easier for you to find what you want.
Just click on a topic you want to read to open it or search for what you want in
the page with Ctrl+f.
Aliases are mIRC's way to define functions.
There are 2 ways to create aliases, the first is to use the the aliases tab in the script editor, which will make all the aliases global (they can be used in all the script files), and you don't declare them as aliases, you just give a name and write the commands in { } brackets.
The second way is to declare the aliases in the remotes section, by using the alias declaration.
Alias [-l] alias_name {
Arguments: $1- = Contains all the text that was sent to the function.
$1,$2,$3 = Retrieves the specified token, divided by
spaces.
Unless the alias was called as an
$identifier(Arg1,Arg2,Arg3)
in which case they will return the
arguments and may contain spaces.
$prop = Retrieves the the property that was used when
calling that alias.
$isid = Returns $true is the alias was called as an
identifier (called with a $)
$show = Returns $true if the alias was called with a . (dot) meaning it
should be quiet.
The -l switch sets the alias as a local alias which can be called
only from that script file.
You can use Return <value> to return a value from an
alias, or use
Halt to stop the process that called the alias .
}
Examples:
Alias echo_text {
echo $1-
}
/echo_text hello world
Alias Power {
var %val = $calc($1 ^ $2)
if ($prop = neg) return $calc(-1 * %val)
else return %val
}
//echo $power(2,4)
//echo $power(2,4).neg
Alias Identifier {
if ($isid) return $1
else echo $2
}
/echo $identifier(Hello world,Check this)
Returns: Hello world
/identifier Hello world
Returns: world
Note the difference with the way mIRC parses the spaces.
This is why when you use /commands you should use $qt(file name) for
example, and in $identifiers
you don't have to use $qt.
The commands in the alias (and in fact in any part of the script) don't
require the / character
before the command name. That character is the command prefix and it's saved
for the editbox
to separate regular text from a command line. And it's not a fixed
character, it can be set in mIRC's
options at: Options > Other > Command prefix .
So if you use the / for commands it might return an error if someone changed
the prefix in his mIRC client.
If you have an alias with the same name as one of mirc's built in commands, you can still call mIRC's default command by using a ! before the command name.
Example:
alias server {
echo -s Connecting: $1-
!server $1-
}
/server irc.server.net
/*This will connect to the server using the alias, and will echo that line*/
/!server irc.server.net
/*This will call mIRC's default server command and connect to the server*/
A list of all the available $identifiers can be found in the
mIRC help file: /help Identifiers
For a list of the commands, type /help and write / in the index.
If -Then -Else
mIRC scripting uses If-else lines just like any other programming
language.The difference is that it has some built in operators that don't
exist and some other scripting languages
if (v1 <operator> [v2]) { commands }
elseif (v1 <operator> [v2]) { commands }
else {
mIRC reads the logical expressions from left to right, so the
"first" expression must exist for mIRC to continue to the next.
This is important when you want to save some CPU, you can put
the "lighter" comparisons in the beginning and hope they'll fail
so mIRC won't go on to the next comparisons.
There are a number of signs you can put between the
comparison expressions to combine them:
&& Means AND
|| Means OR
( ) Combines
expressions as a group
$& Means expression
continues in next line
Parameters ( after the If line ):
$v1 = Returns the last v1 used
$v2 = Returns the last v2 used
<operator> can be:
= or ==
v1 is equal to v2 (It's considered good programming to use == and not just one =)
=== v1 is equal to v2
Case-Sensitive
!= v1 isn't equal to v2
< v1 is smaller/less than v2
<= v1 is smaller/less than or
equal to v2
> v1 is more/greater than v2
>= v1 is more/greater than or
equal to v2
// v2 is a multiple
of v1
\\ v2 is not a
multiple of v1
& Bitwise
comparison
String operators:
isin String v1
exists in string v2
isincs String v1
exists in string v2 Case-Sensitive
iswm Wildcard
string v1 matches string v2
iswmcs Wildcard
string v1 matches string v2 Case-Sensitive
isnum v1 is a
number in the range v2 which is in the form of n1-n2 (if you don't enter v2,
it checks if v1 is a number)
isletter V1 is a
letter in the range v2 which is in the list of letters v2 (if you don't
enter v2, it checks if v1 is a letter)
isalnum
Checks if v1 contains only letters and numbers (v2 is obsolete)
isalpha Checks if
v1 contains only letters (v2 is obsolete)
islower Checks if
v1 contains only lower case letters (v2 is obsolete)
isupper Checks if
v1 contains only upper case letters (v2 is obsolete)
Channel operators:
ison Nickname v1 is
on the channel v2
isop Nickname v1 is
an op on channel v2
ishop Nickname v1
is a half op on channel v2 (helper)
isvoice Nickname v1
is voiced on channel v2
isreg Nickname v1
is a regular nick on channel v2
isban Checks if v1
is banned from channel v2 (according to the internal ban list, /help $ibl)
ischan Checks if
you are on channel v1 (v2 is obsolete)
Auto-lists operators:
isaop
Checks if v1
is a user in your auto-op list for channel v2 (v2 optional)
isavoice
Checks if
v1 is a user in your auto-voice list for channel v2 (v2 optional)
isignore
Checks if
v1 is a user in your ignore list with the ignore switch v2 (v2 optional)
isprotect Checks if v1 is a user in your protect list for channel v2 (v2 optional)
isnotify
Checks if
v1 is a user in your notify list
Boolean Identifiers:
Some of these identifiers have some other functions and props, but they can also be used like this:
$isalias(name) = Returns $true if the alias name exists in your aliases or scripts.
$isbit(A,N) = Returns $true if the Nth bit in the number A is turned on (1).
$isdde(name) = Returns $true if the dde name exists.
$isdir(Path) = Returns $true if the directory path exists.
$isfile(Path\filename.ext) = Returns $true if the file name in the specified location.
$istok(text,token,C) = Returns $true if the token (word) exists in the text with the character separator C.
If (!$isdir($mircdir\Check)) .mkdir $mircdir\Check /* an example for a boolean use of the conditions */
if (!%check) || (!%other) echo -a One of the variables doesn't exist.
Popups are a list of predefined commands that appear
when you right click on a window in mIRC.
Popups are also used to control window mouse events.
Remote Events:
The remote events are mostly triggered by IRC events,
although some of them are triggered by local mIRC events.
These events trigger automatically, and are very useful to automate your
script.
I think it's important we start from the most basic events, and slowly move
toward the more complicated ones.
In some events you can use ^ before the <level> and /haltdef to replace
mIRC's default response.
$event will return the event type in any event triggered.
User levels in mIRC are assigned to users and events to limit a user's access to certain events.
This feature enables you to group users as friends or anything you want, and create events that will be limited to those groups.
The user level is set using the command: /auser [-a] <levels> <nick//address> [info]
The -a switch means that the user levels will be added to the existing levels, without mIRC will redefine the user's levels to the new ones.
The levels are local, and are stored in the Users section in the script editor ( can be accessed with $ulist() ).
For more examples check mIRC's help file.
Example:
/auser -a 5,10,Friend My_friend
/*This command adds the nick My_friend to access levels 5 10 and "Friend"*/
The significance of these levels are easily seen in mIRC's events.
All mIRC events have a <level> parameter in the event's syntax, except for the raw events that are server related..
So, lets divide the levels into 2 categories: Named levels and numeric levels.
Named levels:
Named levels are the easiest, you just enter a level name in the <level> parameter, and the event will trigger only if the user that triggered the event
has the same user level as specified in the event.
There's no need for comparisons, because there isn't a clear hierarchy of levels when you're looking at text level names.
You should avoid using the user level "me" because it's a saved word for user levels (will be explains later on).
Example:
on Friend:join:*: msg $chan Hey there $nick !
/*This event will run only if a user with a user level Friend joins the channel */
Numeric levels:
Numeric levels are much more dynamic, because numbers give you the ability to compare levels, and make events that are accessible to a range of levels.
By default mIRC allows access to events for all the users who have a higher or equal level to that specified in the event (for example on 2: means level 2 and higher).
If there are a number of similar events, with different user levels, mIRC will check for the closest level that matches the triggering user's level.
Here's a list of the available prefixes, comparisons and suffixes:
Prefixes:
* = Allows any user to access the event.
^ = Triggers the event before mIRC's default respond, you can use /haltdef to stop mIRC's default respond.
+level = Limits the event to the specified user level.
me:level: = Triggers the event only if you it was initiated by the local user.
!level = Triggers the event only if it wasn't initiated by the local user.
@level = Triggers if you have ops in the channel that triggered the event.
$level = Means that the <matchtext> parameter contains a regular expression.
&level = Prevents the event from triggering if a /halt or /haltdef command was used in a previous event.
Examples:
on me:5:join:*: msg $chan Hey everybody !
/*This will only run when I join the channel, and I'm level 5 in the level list.*/
on @!100:deop:*: msg $nick Hey buddy, why did you deop $onick without asking me ?
/*Triggers only if you're oped in the channel, you didn't do the deoping, and the user who did is level 100 or above*/
on ^&+5:text:*:*: { echo $target $+(<,$nick,>) Level5 - $1- | haltdef }
/*If a previous script hasn't used /haltdef already, then it will trigger for a level 5 user only, before mIRC's default, and replace the default message text to: <Nick> Level5 - Text */
Comparisons:
Certain events have 2 users associated with the event, so you can use comparisons to check the level differences between the 2 users, we'll call the user who activated the event "the active user", and the target user we'll call "the passive user":
<level = Checks if the active user's level is lower than the passive user's.
<=level = Checks if the active user's level is lower or equal to the passive user's.
>level = Checks if the active user's level is higher than the passive user's.
=>level = Checks if the active user's level is higher or equal to the passive user's.
=level = Checks if the active user's level is equal to the passive user's.
<>level = Checks if the active user's level is Not equal to the passive user's (<> is used instead of != because ! is saved for the prefixes).
Examples:
on !<5:deop:*: msg $nick Hey, $onick is a closed friend than you are, watch out who you deop !
/*This event will run if a user with a level 5 or higher ( and not you ) deops a user with a higher user level*/
on =*:voice:*: msg $nick Hey, why'd you voice him ? he's the same level as you are !
/*This will trigger whenever someone voices another user with the same level as his*/
Suffixes:
Suffixes are used to prevent access to certain events, and they appear in the event's commands, not the <level> parameter.
There are only 2 suffixes:
The = suffix prevents higher level user from accessing lower level events.
The ! suffix prevents mIRC from processing any matching events of that type.
Examples:
on 1:text:*hi*:*: { do stuff }
on 5:text:*hi*:*: =
on 5:text:*hi*:*: {do more stuff }
/*This will prevent any user on level 5 from triggering the associated event from a lower level, but will allow another event for that level to be triggered*/
on 1:text:*hi*:*: { do stuff }
on 5:text:*hi*:*: !
on 5:text:*hi*:*: {do more stuff }
/*This will disable all events for the specified level that match that event. /*